<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #avatar="{ record }">
        <a-avatar>
          <img :src="record.avatar?record.avatar:'/logo.svg'" style="object-fit: cover" />
        </a-avatar>
      </template>

      <template #mobile="{ record }">
        <a-link href="javascript:void(0)"  @click="openUserShow(record.id)" >{{ record.mobile }}</a-link>
      </template>

      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>


    </ma-crud>

    <user-show ref="userShowRef"/>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import userInfo from '@/api/user/userInfo'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'


import userShow from '@/views/user/info/components/showUser.vue'
const userShowRef = ref()
const openUserShow = async (userId) =>{
  userShowRef.value.open(userId)
  return ;
}


const crudRef = ref()





const numberOperation = (newValue, id, numberName) => {
  userInfo.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  userInfo.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'user_info',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: userInfo.getList,
  recycleApi: userInfo.getRecycleList,
  add: {
    show: true,
    api: userInfo.save,
    auth: ['user:info:save']
  },
  edit: {
    show: true,
    api: userInfo.update,
    auth: ['user:info:update']
  },
  delete: {
    show: true,
    api: userInfo.deletes,
    auth: ['user:info:delete'],
    realApi: userInfo.realDeletes,
    realAuth: ['user:info:realDeletes']
  },
  recovery: {
    show: true,
    api: userInfo.recoverys,
    auth: ['user:info:recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    width:80,
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "用户编号",
    width:120,
    dataIndex: "room_no",
    addDisplay: false,
    editDisplay: false,
    formType: "input",
    search: true
  },
  {
    title: "昵称",
    dataIndex: "nickname",
    width:120,
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入昵称"
    }
  },
  {
    title: "上级",
    dataIndex: "pid",
    formType: "input",
    addDisplay: false,
    hide:true
  },
  {
    title: "上级手机号",
    dataIndex: "parent_name",
    width:120,
    editDisplay: false,
    formType: "input",
    addDisplay: false
  },
  {
    title: "头像",
    dataIndex: "avatar",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入头像"
    },
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "手机号",
    dataIndex: "mobile",
    width:140,
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入父节点"
    }
  },
  {
    title: "邮箱",
    dataIndex: "email",
    formType: "input",
    hide:true
  },
  {
    title: "性别",
    dataIndex: "gender",
    formType: "input",
    search: false,
    hide:true
  },
  {
    title: "交易联接",
    dataIndex: "trade_url",
    addDisplay: false,
    editDisplay: false,
    formType: "input",
    search: false,
    hide:true
  },
  {
    title: "用户类型",
    dataIndex: "is_flag",
    editDisplay: false,
    formType: "select",
    dict: { data: [{ label: '测试号', value: 2 }, { label: '散户', value: 1 }], translation: true },
    search: true
  },
  {
    title: "实名",
    dataIndex: "is_real_name",
    dict: { data: [{ label: '实名', value: 2 }, { label: '未实名', value: 1 }], translation: true },
    addDisplay: false,
    editDisplay: false,
    formType: "radio",
    search: true
  },
  {
    title: "最后登陆ip",
    dataIndex: "login_last_ip",
    addDisplay: false,
    width:180,
    formType: "input",
    search: false
  },
  {
    title: "最后登陆时间",
    dataIndex: "login_last_time",
    formType: "date",
    width:180,
    addDisplay: false,
    editDisplay: false,
    showTime: false
  },
  {
    title: "邀请码",
    dataIndex: "invite_code",
    addDisplay: false,
    formType: "input",
    search: true
  },
  {
    title: "来源类型",
    dataIndex: "source_type",
    addDisplay: false,
    editDisplay: false,
    formType: "input",
    search: false,
    hide:true
  },
  {
    title: "用户状态",
    dataIndex: "status",
    formType: "radio",
    dict: { data: [{ label: '禁用', value: 2 },{ label: '冻结', value: 3 }, { label: '正常', value: 1 }], translation: true },
    search: true,
    addDefaultValue: '1',
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "textarea",
    hide: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },

  {
    title: "删除数据",
    dataIndex: "delete_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'user:info' } </script>

<style scoped>

.diagonal-div {
  width: 200px;
  height: 100px;
  background:
      linear-gradient(to right bottom, #ff6347 50%, transparent 50%)
      top left / 50% 100%,
      linear-gradient(to right bottom, transparent 50%, #ff6347 50%)
      bottom right / 100% 50%;
  background-repeat: no-repeat;
}
</style>